//
//  YPBorrowTypeView.m
//  ChengHuiTong
//
//  Created by CHT-Technology on 2017/1/6.
//  Copyright © 2017年 张文权. All rights reserved.
//

#import "YPBorrowTypeView.h"

@implementation YPBorrowTypeView


- (void)setBorrowType:(NSArray *)borrowType{
    
    NSMutableArray *mBorrowType = [NSMutableArray arrayWithArray:borrowType];
    if ([mBorrowType containsObject:@5]) {
        [mBorrowType insertObject:@7 atIndex:[borrowType indexOfObject:@5]];
    }
    if ([mBorrowType containsObject:@10]) {
        NSInteger index = [borrowType indexOfObject:@10];
        [mBorrowType replaceObjectAtIndex:index withObject:[NSNumber numberWithInteger:8]];
    }
    
    //1诚信贷，2城车贷，3约标，4，托管标，5加信贷,6三农贷，10加息劵
    //@""，@“信”，@“抵”，@“约”，@“”，@“保胜+加信贷”，@“加息劵”
    NSArray *picArray = @[@"0",@"believe",@"didi",@"appointment",@"0",@"baosheng",@"nong",@"jiaxin",@"jiaxijuantb"];
    
    while (self.subviews.count < mBorrowType.count) {
        
        UIImageView *imageView = [[UIImageView alloc]init];
        [self addSubview:imageView];
    }
    
    CGFloat finalW = 0;
    CGFloat space = 5;
    for (int i = 0; i < self.subviews.count; i ++) {
        
        UIImageView *imageView = self.subviews[i];
        if (mBorrowType.count > i) {
            NSInteger index = [mBorrowType[i] integerValue];
            if(picArray.count <= index) break;
            imageView.hidden = NO;
            UIImage *image = [UIImage imageNamed:picArray[index]];
            imageView.image = image;
            imageView.size = image.size;
            finalW += imageView.width;
            imageView.right = finalW;
            imageView.top = (self.height - imageView.height)/2.f;
            finalW += space;
        }else{
            imageView.hidden = YES;
        }
    }
    self.width = finalW;
}

@end
